<?php
namespace app\supermanager\controller;

use think\Controller;
use think\Request;
use app\common\traits\controller\TraitUpload;
use app\common\traits\controller\TraitController;
/**
 * 会员管理
 */
class User extends Controller
{
	use TraitUpload;
	use TraitController;
	const WAIT_CHECK = 0;//待审核
	const CHECKED = 1;//审核通过
	const UNCHECKED = -99;//审核未通过

	/**
	 * 初始化操作
	 */
	protected function init()
    {
        if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
    }
	
	//会员信息列表
	public function index()
	{
		$list = model('Users')->getUserList(input('get.'));
		$this->assign('list',$list);
		$branchs = model('Filiales')->column('name','id');
        $this->assign('branchs',$branchs);
		return view('user/index');
	}


	public function read($id)
	{
		$userinfo = model('Users')->getSuperUserInfo($id);//halt($userinfo);
		$this->assign('userinfo',$userinfo);

		$caravan_name = model('Caravans')->where('user_id',$id)->value('name');
		$this->assign('caravan_name',$caravan_name);

		$contactioninfo = db('contactioninfo')->where('user_id',$id)->select();
		$this->assign('contactioninfo',$contactioninfo);//新增联系人

		return view('user/read');
	}

	//////////////////////////////////实名认证模块//////////////////////////////////////
    /**
     * [FunctionName 列表]
     * @param string $value [description]
     */
    public function RZList()
    {
    	$Rzlist = db('user_certification')->select();
		return view('user/rzindex',['Rzlist'=>$Rzlist]);
    }
    /**
     * [FunctionName 查看]
     * @param string $value [description]
     */
    public function RZInfo($id)
    {
    	$info = db('user_certification')->where('id',$id)->find();
    	$rz = db('users')->where('id',$info['user_id'])->value('authentication');
		return view('user/waitrenzh',['info'=>$info,'rz'=>$rz]);
    }
    /**
     * [FunctionName 认证]
     * @param string $value [description]
     */
    public function RZPass()
    {
    	$name = input('post.name');
    	$ID_number = input('post.number');
    	$user_id = db('user_certification')->where('card_id',$ID_number)->value('user_id');
    	$res = model('Authentication')->Check($user_id,$name,$ID_number);
    	if ($res['isok']==1&&$res['code']==1) {
    		$re = db('users')->where('id',$user_id)->setField('authentication',1);
    		if ($re) {
    			return $this->success($res['messsage'],'/users');
    		}
    	}else{
    		return $this->error($res['messsage']);
    	}
    }
}